<template>
	<view class="card_box">
		<uni-card v-if="authorData?.nickName" @click="goUserInfo" :title="authorData?.nickName" :thumbnail="authorData?.headImgUrl">
			<template v-slot:actions>
					<view class="card-actions">
						<view class="card-actions-item" >
							<view class="top">
								<uni-icons type="hand-up" size="25" color="#999"></uni-icons>
								<text class="card-actions-item-text">{{userCollectData.starNum}}</text>
							</view>
							<view class="bottom">
								<text class="card-actions-item-text">被点赞数</text>
							</view>
						</view>
						<view class="card-actions-item" >
							<view class="top">
								<uni-icons type="chat" size="25" color="#999"></uni-icons>
								<text class="card-actions-item-text">{{userCollectData.commentNum}}</text>
							</view>
							<view class="bottom">
								<text class="card-actions-item-text">被评论数</text>
							</view>
						</view>
						<view class="card-actions-item" >
							<view class="top">
								<uni-icons type="eye" size="25" color="#999"></uni-icons>
								<text class="card-actions-item-text">{{userCollectData.viewsNum}}</text>
							</view>
							<view class="bottom">
								<text class="card-actions-item-text">被浏览数</text>
							</view>
						</view>
					</view>
				</template>
		</uni-card>
		<uni-card v-else @click="goUserInfo" title="登录" thumbnail="https://file.lddcc.cn/h.jpg">
		</uni-card>
	</view>
</template>

<script setup>
	import {ref, watch} from 'vue'
	import { onShow } from '@dcloudio/uni-app'
	import {UserModel} from '@/service/model/user.js'
	const userModel = new UserModel()
	const userCollectData=ref({})
	const props=defineProps({
		authorData:{
			type:Object
		},
		type:{
			type:String
		}
	})
	watch(props,()=>{
		getUserDataFun()
	})
	const getUserDataFun=async ()=>{
		const {data,success}=await userModel.getUserData({userId:props.authorData?.userId})
		if(success){
			userCollectData.value=data
		}
	}
	const goUserInfo=()=>{
		if(props.type==='self' && props.authorData?.nickName){
			uni.navigateTo({
				url:"/pages/UserCenter/UserInfo/UserInfo"
			})
		}else{
			uni.navigateTo({
				url:'/pages/UserCenter/Login/Login'
			})
		}
	}
</script>

<style lang="less">
	.card_box{
		.card-actions{
			display: flex;
			justify-content: space-between;
			.card-actions-item{
				display: flex;
				flex-direction: column;
				align-items: center;
				.top{
					display: flex;
					align-items: center;
					.card-actions-item-text{
						margin-left: 4rpx;
						color: #9E9E9E;
						font-size: 30rpx;
					}
				}
				.bottom{
					display: flex;
					justify-content: center;
					.card-actions-item-text{
						color: #9E9E9E;
						font-size: 30rpx;
					}
				}
			}
		}
	}
</style>